home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Installer SDK Cornucopia 1.0.2 / Script Examples / Action Atoms [inaa] Example / progressAtom.c < prev    next >
Encoding:
Text File  |  1996-09-10  |  4.9 KB  |  127 lines  |  [TEXT/MPS ]

  1. //
  2. //    ProgressAtom.c
  3. //
  4. //        Demonstration of a format2 action atom displaying 
  5. //        advancement of the installer dialog progress bar.
  6. //
  7. //        When the action atom will take a long time to complete its task(s), 
  8. //        it is a good idea to present the user with some kind of comforting 
  9. //        sign that the machine is performing normally. Using the methods outlined 
  10. //        in this example, scriptwriters can show progress in the bar
  11. //        displayed in the installer dialog.
  12. //
  13. //        Every format2 action atom is allocated 100 increments
  14. //        from the installer progress bar to use as the action atom 
  15. //        performs its duties. Error checking is performed by the installer
  16. //        so that even if the action atom requests progress display 
  17. //        beyond the 100 allotted increments, the installer will 
  18. //        limit the progress to 100 increments.
  19. //
  20. //        It should be noted that although there are 100 increments
  21. //        alloted to the action atom, progress is not displayed with
  22. //        each and every increment registered from the action atom.
  23. //
  24. //        Copyright 1993-1996, Apple Computer, Inc., All Rights Reserved
  25. //
  26.  
  27. #include <Traps.h>
  28. #include <Types.h>
  29. #include <dialogs.h>
  30. #include <TextUtils.h>
  31.  
  32. // this line has been added for Wasabi Installer Debugger support
  33. #include "ActionHandlerHeader.h"
  34.  
  35. // this line replaces #include "ActionAtomHeader.h" used in previous 4.0.3 action atoms
  36. #include "InstallerScript.h"
  37.  
  38. // this is needed for highlighting the default button in dialog
  39. pascal OSErr SetDialogDefaultItem (    DialogPtr theDialog,
  40.                                     short newItem         ) = {0x303C,0x0304,0xAA68};
  41.  
  42. // this is used to print one line out to the Wasabi Installer Debugger 
  43. void PrintLine( InstallerCallBackUPP pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 );
  44.  
  45. // print the parameter block record information to Wasabi Installer Debugger
  46. void PrintAAParamBlock( ActionAtom2PBPtr atomRecPtr );
  47.  
  48. // NOTE: The name of this function 'ActionAtomFormat2' should
  49. // match that specified in the -m option for the line in the
  50. // makefile that compiles this action atom.
  51. ActionAtomResult ActionAtomFormat2( ActionAtom2PBPtr atomRecPtr )
  52. {
  53.     short        i = 0;                    // 0..100 progress bar increments    
  54.     long        lastTickCount = 0;        // last check at the time
  55.     long        currentTickCount = 0;    // this check at the time
  56.     
  57.     // print the parameter block record information to Wasabi Installer Debugger
  58.     PrintAAParamBlock( atomRecPtr );
  59.  
  60.     while ( i < 100 )
  61.         {
  62.         // get the time in ticks
  63.         lastTickCount = currentTickCount = TickCount();
  64.         
  65.         // wait five seconds ( non-CPU specific method )
  66.         while ( currentTickCount < ( lastTickCount + 5 ))
  67.             // keep getting the time in ticks
  68.             currentTickCount = TickCount();
  69.         
  70.         // tell the silly progress bar to move along
  71.         IncrementStatusBar( atomRecPtr->fCallBackProcPtr, 1 );
  72.         i++;
  73.         }
  74.  
  75.     // print the return value to Wasabi Installer Debugger
  76.     PrintLine( atomRecPtr->fCallBackProcPtr, "\p\n", 
  77.                 "\pProgress Bar Action Atom - done - returning 0 ...", "\p\n", "\p" );
  78.  
  79.     return( 0 );
  80.  
  81. }
  82.  
  83. // shoot one line of text out to the Wasabi Installer Debugger
  84. void PrintLine( InstallerCallBackUPP pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 )
  85. {
  86.     long    theResult;
  87.     RegisterScriptAction( pCallBackProcPtr, kDebuggingAction, kGenericDebugActID, pParam0, pParam1, pParam2, pParam3, &theResult );    
  88. }
  89.  
  90. void PrintAAParamBlock( ActionAtom2PBPtr atomRecPtr )
  91. {
  92.     Str255        numStr;
  93.     
  94.     PrintLine( atomRecPtr->fCallBackProcPtr, "\p\n", "\pParameter Block for Progress Bar Action Atom ...", "\p", "\p" );
  95.     
  96.     NumToString( atomRecPtr->fMessageID, numStr );
  97.     PrintLine(   atomRecPtr->fCallBackProcPtr, "\p", "\pfMessageID : ", numStr,  "\p" );
  98.     
  99.     NumToString( (long) atomRecPtr->fStaticDataHdl, numStr );
  100.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfStaticDataHdl : ", numStr, "\p", "\p" );
  101.     
  102.     NumToString( (long) atomRecPtr->fTargetVRefNum, numStr );
  103.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfTargetVRefNum : ", numStr, "\p", "\p" );
  104.     
  105.     NumToString( (long) atomRecPtr->fTargetFolderDirID, numStr );
  106.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfTargetFolderDirID : ", numStr, "\p", "\p" );
  107.     
  108.     NumToString( (long) atomRecPtr->fSystemVRefNum, numStr );
  109.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfSystemVRefNum : ", numStr, "\p", "\p" );
  110.     
  111.     NumToString( (long) atomRecPtr->fSystemBlessedDirID, numStr );
  112.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfSystemBlessedDirID : ", numStr, "\p", "\p" );
  113.     
  114.     NumToString( (long) atomRecPtr->fRefCon, numStr );
  115.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfRefCon : ", numStr, "\p", "\p" );
  116.     
  117.     NumToString( (long) atomRecPtr->fDoingInstall, numStr );
  118.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfDoingInstall : ", numStr, "\p", "\p" );
  119.     
  120.     NumToString( (long) atomRecPtr->fDidLiveUpdate, numStr );
  121.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfDidLiveUpdate : ", numStr, "\p", "\p" );
  122.     
  123.     NumToString( (long) atomRecPtr->fInstallerTempDirID, numStr );
  124.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfInstallerTempDirID : ", numStr, "\p", "\p\n" );
  125.     
  126. }
  127.